package POE::Component::Gearman::Job;

use strict;
use warnings;

use Smart::Comments;

sub new {
    my $class = shift;
    my %args = @_;

    # TODO: 参数校验

    return bless \%args, $class;
}

sub workload {
    my $self = shift;

    return $self->{workload};
}

sub data {
    my $self = shift;
    my $data = shift || return;

    $self->{callback}->( WORK_DATA => $data );
}

sub warning {
    my $self = shift;
    my $data = shift || '';

    $self->{callback}->( WORK_WARNING => $data );
}

sub status {
    my $self = shift;
    my $numerator = shift || 0;
    my $denominator = shift || 100;

    $self->{callback}->( WORK_STATUS => $numerator, $denominator );
}

sub complete {
    my $self = shift;
    my $data = shift || '';

    $self->{callback}->( WORK_COMPLETE => $data );
}

sub fail {
    my $self = shift;

    $self->{callback}->( 'WORK_FAIL' );
}

sub exception {
    my $self = shift;
    my $data = shift || '';

    $self->{callback}->( WORK_EXCEPTION => $data );
}

1;
